package com.xyz.aclservice.controller;


import com.xyz.aclservice.entity.EduPermission;
import com.xyz.aclservice.service.EduPermissionService;
import com.xyz.entity.R;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限 菜单管理
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Schema(description="菜单权限管理接口")
@RestController
@RequestMapping("/admin/acl/permission")
//@CrossOrigin
public class EduPermissionController {

    @Autowired
    private EduPermissionService eduPermissionService;

    //获取全部菜单
    @Schema(description = "查询所有菜单")
    @GetMapping
    public R indexAllPermission() {
        List<EduPermission> list =  eduPermissionService.queryAllMenu();
        return R.ok().data("children",list);
    }

    @Schema(description="递归删除菜单")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id) {
        eduPermissionService.removeChildById(id);
        return R.ok();
    }

    @Schema(description="给角色分配权限")
    @PostMapping("/doAssign")
    public R doAssign(String roleId,String[] permissionId) {
        eduPermissionService.saveRolePermissionRealtionShip(roleId,permissionId);
        return R.ok();
    }

    @Schema(description="根据角色获取菜单")
    @GetMapping("toAssign/{roleId}")
    public R toAssign(@PathVariable String roleId) {
        List<EduPermission> list = eduPermissionService.selectAllMenu(roleId);
        return R.ok().data("children", list);
    }



    @Schema(description="新增菜单")
    @PostMapping("save")
    public R save(@RequestBody EduPermission eduPermission) {
        eduPermissionService.save(eduPermission);
        return R.ok();
    }

    @Schema(description="修改菜单")
    @PutMapping("update")
    public R updateById(@RequestBody EduPermission eduPermission) {
        eduPermissionService.updateById(eduPermission);
        return R.ok();
    }

}

